package com.baizhi.service.impl;

import com.baizhi.dao.GuruDAO;
import com.baizhi.entity.Guru;
import com.baizhi.service.GuruService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class GuruServiceImpl implements GuruService {
    @Autowired
    private GuruDAO guruDAO;
    @Override
    public List<Guru> selectAllGuru() {
        List<Guru> gurus = guruDAO.selectAllGuru();
        return gurus;
    }

    @Override
    public PageInfo<Guru> selectAll(String name, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Guru> gurus = guruDAO.selectAll(name);
        PageInfo<Guru> pageInfo = new PageInfo<>(gurus);
        return pageInfo;
    }

    @Override
    public Boolean insertGuru(Guru guru) {
        Boolean a = null;
        try{
            guruDAO.insertGuru(guru);
            a = true;
        }catch(Exception e){
            a = false;
        }
        return a;
    }

    @Override
    public Boolean updateGuru(Guru guru) {
        Boolean a = null;
        try{
            guruDAO.updateGuru(guru);
            a = true;
        }catch(Exception e){
            a = false;
        }
        return a;
    }

    @Override
    public Guru selectOneGuru(Integer id) {
        Guru guru = guruDAO.selectOneGuru(id);
        return guru;
    }

    @Override
    public void insertAll(List<Guru> gurus) {
        guruDAO.insertAll(gurus);
    }
}
